<?php
namespace Logic;

use Library\Db;
use Library\Log;
use Library\Redis;
use Model\Cnf;


class CnfLogic extends BaseLogic {
	/**
	 * test
	 * @return string
	 */
	static public function test() {
		return __METHOD__;
	}


	/**
	 * 根据type，查询k=>v列表
	 * @param string $type
	 */
	static public function getKvListByType($type) {
		$redis_key = "cnf:$type";
		if (!Redis::exists($redis_key)) {
			$cnf_list = Cnf::getCnfListByType($type);
			if (!$cnf_list) {
				Log::info(__METHOD__ . ': There is no cnf of type: ' . $type);
				return false;
			}
			$result = [];
			foreach ($cnf_list as $cnf) {
				$result[$cnf['k']] = $cnf['v'];
			}
			Redis::hmset($redis_key, $result);
		}
		return Redis::hgetall($redis_key);
	}




}